import { SerializeStream } from "../Serialize/SerializeStream";
import { HandlerId } from "./HandlerId";
//class SeqHandlerIdHelper

export class SeqHandlerIdHelper {
  public static write(stream: SerializeStream, datas: Array<HandlerId>): void {
    var i = 0;
    if (datas != null) {
      stream.writeSize(datas.length);
      i = 0;
      while (i < datas.length) {
        let handlerId = datas[i] as HandlerId;
        handlerId.__write(stream);
        ++i;
      }
    } else {
      stream.writeSize(0);
    }
  }

  public static read(stream: SerializeStream): Array<HandlerId> {
    SeqHandlerIdHelper._testAry.length = 0;
    var ary = SeqHandlerIdHelper._testAry;
    var size = stream.readSize();
    stream.checkFixedSeq(size, 8);
    var i = 0;
    while (i < size) {
      let handlerId = new HandlerId();
      handlerId.__read(stream);
      ary[i] = handlerId;
      ++i;
    }
    return ary;
  }

  private static _testAry: Array<HandlerId> = [];
}
